<template>
	<view class="content">
		<textarea v-model="title" placeholder="请说说你的看法..." placeholder-class="beforeClass" />
		<view class="cont">
			<view class="title" :class="[article.imgList ? 'titleShort':'']">{{article.title}}</view>
			<image :src="article.imgList.length > 0 ? article.imgList[0] : article.avatar ? article.avatar : defimg" mode=""></image>
		</view>
	</view>
</template>

<script>
	import util from '@/common/util.js';
	export default{
		data() {
			return {
				article_id: '',
				article: {},
				title: '',
				stateType: '', // 0为默认抖教文章
				addType: '', //附加条件: 0+0为首页抖教推荐  0+1为智囊团  1+3为家文化&孩子-目标、成长、才艺  2+2为育儿经&育儿经-我的  3+4为我的智囊团
				users_type: -1
			}
		},
		onNavigationBarButtonTap(e) {
			if(e.index == 0) {
				uni.navigateBack({
					delta: 1
				})
			} else {
				this.forward();
			}
		},
		onLoad(e) {
			this.stateType = e.stateType;
			this.addType = e.addType;
			this.article_id = e.article_id;
			this.users_type = e.users_type
			this.getDetail();
		},
		methods:{
			/* 获取文章详情 */
			getDetail() {
				var data = {
					article_id: this.article_id
				}
				if (this.users_type && this.users_type >= 0) {
					data.users_type = this.users_type
				}
				var url = '';
				if(this.addType == 1) {
					url = 'user/wisdom.Lists/articleList';
				} else {
					url = 'user/article.Lists/articleList';
				}
				this.$zapi.apiPost(url, data).then(res => {
					if (res.data.code == 200) {
						this.article = res.data.data.data[0];
					} else {
						this.article = {}
						uni.showToast({
							title: '暂时无法转发该文章',
							icon: 'none'
						})
						setTimeout(e => {
							uni.navigateBack({
								delta: 1
							})
						},800)
					}
				})
			},
			forward() {
				var data = {
					article_id: this.article_id
				}
				if(this.title) {
					data.title = this.title
				}
				var url = '';
				if(this.addType == 1) {
					url = 'user/wisdom.Lists/transmitArticle';
				} else {
					url = 'user/article.Lists/transmitArticle';
				}
				this.$zapi.apiPost(url,data).then(res=>{
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
					if(res.data.code == 200) {
						setTimeout(function() {
							uni.navigateBack({
								delta: 2
							})
						}, 1000);
					}
				})
			}
		}
	}
</script>

<style>
	page{
		padding: 30upx;
		width: 690upx;
	}
	.beforeClass{
		color: #CCCCCC;
		font-size: 32upx;
	}
	textarea{
		width: 100%;
		min-height: 200upx;
	}
	.cont{
		width: 100%;
		height: 120upx;
		background: #FAFAFA;
		margin-top: 30upx;
		display: flex;
		justify-content: space-between;
	}
	.title{
		width: 100%;
		color: #333333;
		font-size: 32upx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		padding: 20upx;
	}
	.titleShort{
		width: 75%;
	}
	image{
		width: 120upx;
		height: 120upx;
	}
</style>
